import { Component, ChangeDetectorRef } from "@angular/core";
import { NavController, NavParams } from "ionic-angular";
import { HttpService } from "./../../providers/http.service";
import { CommonFunc } from "./../../providers/commonFunc";
import { Storage } from "@ionic/storage";
import { SignPage } from "../sign/sign";
import { ApplyRepairDetailPage } from "../repair-apply-detail/apply-repair-detail";

@Component({
  templateUrl: "repair-apply-list.html"
})
export class RepairApplyList {
  private title: string; //标题
  private list: any = [];
  private pageSize: number = 10;
  private currentPage: number = 1;
  private currentUserId: any;
  constructor(
    private navParams: NavParams,
    private commonFunc: CommonFunc,
    private httpService: HttpService,
    private storage: Storage,
    private navController: NavController,
    public cd: ChangeDetectorRef
  ) {
    this.title = "待修理单子";
    this.storage.get("user").then(data => {
      let param = {
        approveStatus: "1",
        dealStatus: "0",
        elevatorId: this.navParams.get("elevatorId"),
        userId: data.id
      };
      this.httpService.getRepairApplyList(param).subscribe(data => {
        if (data.status != 200) {
          let toast = this.commonFunc.showInsideErrorToast(data);
          toast.present();
          return;
        }
        this.list = data.data.list;
        this.cd.detectChanges();
      });
    });
  }

  // //刷新
  // doRefresh(refresher) {
  //     setTimeout(()=>{
  //         this.currentPage++;
  //         let params:any={};
  //         params.pageSize=this.pageSize;
  //         params.currentPage=this.currentPage;
  //         params.currentUserId = this.currentUserId;
  //         params.isRead = '0';
  //         if(this.navParams.get('param')=='1'){
  //             let ob = this.httpService.noticeQueryList(params);
  //             ob.subscribe(data=>{
  //                 if (data.status !=200) {
  //                     let toast = this.commonFunc.showInsideErrorToast(data.message);
  //                     toast.present();
  //                     return;
  //                 }
  //                 if(data.data.list && data.data.list.length>0){
  //                     if(data.data.list){
  //                         data.data.list.forEach(e=>{
  //                             this.list.unshift(e);
  //                         });
  //                     }
  //                 }else{
  //                     refresher.enabled = false;
  //                     // setTimeout(()=> {
  //                     //     refresher.enabled = true;
  //                     // },3000);

  //                 }
  //             })
  //         }else{
  //             let ob = this.httpService.informationQueryList(params);
  //             ob.subscribe(data=>{
  //                 if (data.status !=200) {
  //                     let toast = this.commonFunc.showInsideErrorToast(data.message);
  //                     toast.present();
  //                     return;
  //                 }

  //                 if(data.data.list && data.data.list.length>0){
  //                     if(data.data.list){
  //                         data.data.list.forEach(e=>{
  //                             this.list.unshift(e);
  //                         });
  //                     }
  //                 }else{
  //                     refresher.enabled = false;
  //                     // setTimeout(()=> {
  //                     //     refresher.enabled = true;
  //                     // },3000);

  //                 }

  //             })
  //         }

  //         refresher.complete();
  //     },500);
  // }

  detail(p) {
    this.navController.push(ApplyRepairDetailPage, { id: p.id, dtype: "wx" });
  }
}
